package com.danco.training.zaneuskaya.serialization;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;

import org.apache.log4j.Logger;

import com.danco.training.zaneuskaya.annotation.ConfigProperty;
import com.danco.training.zaneuskaya.annotation.ConfigPropertyAnalizer;

public class FileLoaderUtil {

	@ConfigProperty(configName = { "test.properties", "bookshop.properties" }, propertyName = "serializationfile")
	public static String SERIALIZATION_FILE_NAME_PROPERTY;

	private static ObjectInputStream ois;

	private static final Logger logger = Logger.getLogger(FileLoaderUtil.class);

	public FileLoaderUtil() {
		ConfigPropertyAnalizer.configPropertyAnalizer(this);
	}

	public static Object load() {
		new FileLoaderUtil();
		try {

			FileInputStream is = new FileInputStream(
					SERIALIZATION_FILE_NAME_PROPERTY);
			ois = new ObjectInputStream(is);
			while (is.available() > 0) {
				Object object = ois.readObject();

				return object;
			}
		} catch (ClassNotFoundException e) {
			logger.error(e.getMessage(), e);
		} catch (IOException e) {
			logger.error(e.getMessage(), e);

		}

		

		return null;

	}

}
